/**
 * Copyright (C) 2011  Robin Dietrich, Nils Kenneweg, Leonard Stutz
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 **/
#ifndef MAINAPPLICATION_HPP
#define MAINAPPLICATION_HPP

#include "BaseApplication.hpp"
#include "RenderHelper.cpp"

#include <list>

namespace minecraft {

	class MainApplication : public BaseApplication {
		public:
			MainApplication(void);
			virtual ~MainApplication(void);
		protected:
			int currentPosX;
			int currentPosY;
			int currentPosZ;		
			
			int RenderHelperTime;
            
            CEGUI::Window *inventory;
            CEGUI::Window *frames;
			
			Ogre::SceneNode* box;
			
			boost::unordered_set<std::string> rendering;
		
			boost::unordered_set<coordinate> getList;
			boost::mutex getList_lock;
			
			boost::unordered_set<coordinate> renderList;
			boost::mutex renderList_lock;
			
			boost::unordered_set<Ogre::ManualObject*> drawList;
			boost::mutex drawList_lock;
			
			boost::unordered_set<coordinate> updateList;
			boost::mutex updateList_lock;
			
			boost::unordered_map<coordinate, bool> activeList;
			boost::mutex activeList_lock;
			
			RenderHelper *renderer;
		
			bool started;
			int rounds;
			bool update_chunk;
		
            void getAdd(int x, int y, int z);
			
			void getAdd(int x, int y, int z, bool doUpdate);
		
			void getWorker();
		
			void doDraw(int x, int y, int z);
			void doRendering();

			virtual bool mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id );
			virtual bool mouseMoved( const OIS::MouseEvent &arg );
			
			virtual void createScene(void);
            bool startEvt(const CEGUI::EventArgs &e);
            bool keyPressed( const OIS::KeyEvent &arg );
            bool invEvt(const CEGUI::EventArgs &e);
			virtual bool frameRenderingQueued(const Ogre::FrameEvent& evt);
			Ogre::Vector3* lastPosition;
			std::list<Ogre::ManualObject*> activeChunks;
			std::list<Ogre::SceneNode*> activeNodes;
			float getIntersection(float fDst1, float fDst2, Ogre::Vector3 *P1, Ogre::Vector3 *P2);
	};
}

#endif // #ifndef TESTAPPLICATION_HPP
